<!DOCTYPE html>
<html id="docs" lang="en" class="">
	<head>
	<meta charset="utf-8">
<title>Configure a Pod to Use a ConfigMap - Kubernetes</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" type="image/png" href="../../../../images/favicon.png">
<link rel="stylesheet" type="text/css" href="../../../../css/base_fonts.css">
<link rel="stylesheet" type="text/css" href="../../../../css/styles.css">
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css">
<link rel="stylesheet" type="text/css" href="../../../../css/callouts.css">
<link rel="stylesheet" type="text/css" href="../../../../css/custom-jekyll/tags.css">




<meta name="description" content="Configure a Pod to Use a ConfigMap" />
<meta property="og:description" content="Configure a Pod to Use a ConfigMap" />

<meta property="og:url" content="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" />
<meta property="og:title" content="Configure a Pod to Use a ConfigMap - Kubernetes" />

<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
<script src="../../../../js/script.js"></script>
<script src="../../../../js/custom-jekyll/tags.js"></script>


	</head>
	<body>
		<div id="cellophane" onclick="kub.toggleMenu()"></div>

<header>
    <a href="../../../../index.html" class="logo"></a>

    <div class="nav-buttons" data-auto-burger="primary">
        <ul class="global-nav">
            
            
            <li><a href="../../../home.1">Documentation</a></li>
            
            <li><a href="../../../../blog/index.html">Blog</a></li>
            
            <li><a href="../../../../partners/index.html">Partners</a></li>
            
            <li><a href="../../../../community/index.html">Community</a></li>
            
            <li><a href="../../../../case-studies/index.html">Case Studies</a></li>
            
            
             <li>
                <a href="index.html#">
                    English <span class="ui-icon ui-icon-carat-1-s"></span>
                </a>
                <ul>
                
                    <li><a href="../../../../zh/index.html">中文 Chinese</a></li>
                
                    <li><a href="../../../../ko/index.html">한국어 Korean</a></li>
                
                </ul>
            </li>
         
            <li>
                <a href="index.html#">
                    v1.11 <span class="ui-icon ui-icon-carat-1-s"></span>
                </a>
                <ul>
                
                    <li><a href="https://kubernetes.io">v1.12</a></li>
                
                    <li><a href="../../../../index.html">v1.11</a></li>
                
                    <li><a href="https://v1-10.docs.kubernetes.io">v1.10</a></li>
                
                    <li><a href="https://v1-9.docs.kubernetes.io">v1.9</a></li>
                
                </ul>
            </li>
        </ul>
        
        <a href="../../../tutorials/kubernetes-basics/index.html" class="button" id="tryKubernetes" data-auto-burger-exclude>Try Kubernetes</a>
        <button id="hamburger" onclick="kub.toggleMenu()" data-auto-burger-exclude><div></div></button>
    </div>

    <nav id="mainNav">
        <main data-auto-burger="primary">
        <div class="nav-box">
            <h3><a href="../../../tutorials/stateless-application/hello-minikube/index.html">Get Started</a></h3>
            <p>Ready to get your hands dirty? Build a simple Kubernetes cluster that runs "Hello World" for Node.js.</p>
        </div>
        <div class="nav-box">
            <h3><a href="../../../home.1">Documentation</a></h3>
            <p>Learn how to use Kubernetes with the use of walkthroughs, samples, and reference documentation. You can even <a href="../../../../editdocs/index.html" data-auto-burger-exclude>help contribute to the docs</a>!</p>
        </div>
        <div class="nav-box">
            <h3><a href="../../../../community/index.html">Community</a></h3>
            <p>If you need help, you can connect with other Kubernetes users and the Kubernetes authors, attend community events, and watch video presentations from around the web.</p>
        </div>
        <div class="nav-box">
            <h3><a href="../../../../blog/index.html">Blog</a></h3>
            <p>Read the latest news for Kubernetes and the containers space in general, and get technical how-tos hot off the presses.</p>
        </div>
        </main>
        <main data-auto-burger="primary">
        <div class="left">
            <h5 class="github-invite">Interested in hacking on the core Kubernetes code base?</h5>
            <a href="https://github.com/kubernetes/kubernetes" class="button" data-auto-burger-exclude>View On Github</a>
        </div>

        <div class="right">
            <h5 class="github-invite">Explore the community</h5>
            <div class="social">
                <a href="https://twitter.com/kubernetesio" class="twitter"><span>Twitter</span></a>
                <a href="https://github.com/kubernetes/kubernetes" class="github"><span>Github</span></a>
                <a href="http://slack.k8s.io/" class="slack"><span>Slack</span></a>
                <a href="http://stackoverflow.com/questions/tagged/kubernetes" class="stack-overflow"><span>Stack Overflow</span></a>
                <a href="https://discuss.kubernetes.io" class="mailing-list"><span>Forum</span></a>
                <a href="https://calendar.google.com/calendar/embed?src=nt2tcnbtbied3l6gi2h29slvc0%40group.calendar.google.com" class="calendar"><span>Events Calendar</span></a>
            </div>
        </div>
        <div class="clear" style="clear: both"></div>
        </main>
    </nav>
</header>

		
		
		<section id="hero" class="light-text no-sub">
			











<h1>Tasks</h1>
<h5></h5>






<div id="vendorStrip" class="light-text">
	<ul>
		
		
		<li><a href="../../../home.1">DOCUMENTATION</a></li>
		
		
		<li><a href="../../../setup/index.html">SETUP</a></li>
		
		
		<li><a href="../../../concepts/index.html">CONCEPTS</a></li>
		
		
		<li><a href="../../index.html" class="YAH">TASKS</a></li>
		
		
		<li><a href="../../../tutorials/index.html">TUTORIALS</a></li>
		
		
		<li><a href="../../../reference.1">REFERENCE</a></li>
		
	</ul>
	<div id="searchBox">
		<input type="text" id="search" placeholder="Search" onkeydown="if (event.keyCode==13) window.location.replace('/docs/search/?q=' + this.value)" autofocus="autofocus">
	</div>
</div>

		</section>
		
		
<section id="deprecationWarning">
  <main>
    <div class="content deprecation-warning">
      <h3>
        Documentation for Kubernetes v1.11 is no longer actively maintained. The version you are currently viewing is a static snapshot.
        For up-to-date documentation, see the <a href="https://kubernetes.io/docs/home/">latest</a> version.
      </h3>
    </div>
  </main>
</section>


		<section id="encyclopedia">
			
<div id="docsToc">
     <div class="pi-accordion">
    	
        
        
        
        
        
         
             
                 
             
         
             
                 
             
         
             
                 
             
         
             
                 
             
         
             
                 
                          
                          
                 
             
         
             
         
             
         
             
         
         
        
        <a class="item" data-title="Tasks" href="../../index.html"></a>

	
	
		
		
	<div class="item" data-title="Install Tools">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Install and Set Up kubectl" href="../../kubectl/install/index.html"></a>

		
	
		
		
<a class="item" data-title="Install Minikube" href="../../tools/install-minikube/index.html"></a>

		
	
		
		
<a class="item" data-title="Installing kubeadm" href="../../../setup/independent/install-kubeadm/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Configure Pods and Containers">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Assign Memory Resources to Containers and Pods" href="../assign-cpu-ram-container"></a>

		
	
		
		
<a class="item" data-title="Assign CPU Resources to Containers and Pods" href="../assign-cpu-resource/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure Quality of Service for Pods" href="../quality-service-pod/index.html"></a>

		
	
		
		
<a class="item" data-title="Assign Extended Resources to a Container" href="../extended-resource/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure a Pod to Use a Volume for Storage" href="../configure-volume-storage/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure a Pod to Use a PersistentVolume for Storage" href="../configure-persistent-volume-storage/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure a Pod to Use a Projected Volume for Storage" href="../configure-projected-volume-storage/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure a Security Context for a Pod or Container" href="../../../user-guide/security-context"></a>

		
	
		
		
<a class="item" data-title="Configure Service Accounts for Pods" href="../../../user-guide/service-accounts"></a>

		
	
		
		
<a class="item" data-title="Pull an Image from a Private Registry" href="../pull-image-private-registry/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure Liveness and Readiness Probes" href="../../../user-guide/liveness/index.html"></a>

		
	
		
		
<a class="item" data-title="Assign Pods to Nodes" href="../assign-pods-nodes/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure Pod Initialization" href="../configure-pod-initialization/index.html"></a>

		
	
		
		
<a class="item" data-title="Attach Handlers to Container Lifecycle Events" href="../attach-handler-lifecycle-event/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure a Pod to Use a ConfigMap" href="index.html"></a>

		
	
		
		
<a class="item" data-title="Share Process Namespace between Containers in a Pod" href="../share-process-namespace/index.html"></a>

		
	
		
		
<a class="item" data-title="Translate a Docker Compose File to Kubernetes Resources" href="../translate-compose-kubernetes/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Administer a Cluster">
		<div class="container">
		
		
	
	
		
		
	<div class="item" data-title="Administration with kubeadm">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Upgrading kubeadm HA clusters from 1.9.x to 1.9.y" href="../../administer-cluster/kubeadm/kubeadm-upgrade-ha/index.html"></a>

		
	
		
		
<a class="item" data-title="Upgrading kubeadm clusters from 1.7 to 1.8" href="../../administer-cluster/kubeadm/kubeadm-upgrade-1-8/index.html"></a>

		
	
		
		
<a class="item" data-title="Upgrading kubeadm clusters from v1.10 to v1.11" href="../../administer-cluster/kubeadm/kubeadm-upgrade-1-11/index.html"></a>

		
	
		
		
<a class="item" data-title="Upgrading/downgrading kubeadm clusters between v1.8 to v1.9" href="../../administer-cluster/kubeadm/kubeadm-upgrade-1-9/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Manage Memory, CPU, and API Resources">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Configure Default Memory Requests and Limits for a Namespace" href="../limit-range/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure Default CPU Requests and Limits for a Namespace" href="../../administer-cluster/cpu-default-namespace/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure Minimum and Maximum Memory Constraints for a Namespace" href="../../administer-cluster/memory-constraint-namespace/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure Minimum and Maximum CPU Constraints for a Namespace" href="../../administer-cluster/cpu-constraint-namespace/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure Memory and CPU Quotas for a Namespace" href="../../administer-cluster/quota-memory-cpu-namespace/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure a Pod Quota for a Namespace" href="../../administer-cluster/quota-pod-namespace/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Install a Network Policy Provider">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Use Calico for NetworkPolicy" href="../../administer-cluster/network-policy-provider/calico-network-policy/index.html"></a>

		
	
		
		
<a class="item" data-title="Use Cilium for NetworkPolicy" href="../../administer-cluster/network-policy-provider/cilium-network-policy/index.html"></a>

		
	
		
		
<a class="item" data-title="Use Kube-router for NetworkPolicy" href="../../administer-cluster/network-policy-provider/kube-router-network-policy/index.html"></a>

		
	
		
		
<a class="item" data-title="Romana for NetworkPolicy" href="../../administer-cluster/network-policy-provider/romana-network-policy/index.html"></a>

		
	
		
		
<a class="item" data-title="Weave Net for NetworkPolicy" href="../../administer-cluster/network-policy-provider/weave-network-policy/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
<a class="item" data-title="Access Clusters Using the Kubernetes API" href="../../administer-cluster/access-cluster-api/index.html"></a>

		
	
		
		
<a class="item" data-title="Access Services Running on Clusters" href="../../administer-cluster/access-cluster-services/index.html"></a>

		
	
		
		
<a class="item" data-title="Advertise Extended Resources for a Node" href="../../administer-cluster/extended-resource-node/index.html"></a>

		
	
		
		
<a class="item" data-title="Autoscale the DNS Service in a Cluster" href="../../administer-cluster/dns-horizontal-autoscaling/index.html"></a>

		
	
		
		
<a class="item" data-title="Change the Reclaim Policy of a PersistentVolume" href="../../administer-cluster/change-pv-reclaim-policy/index.html"></a>

		
	
		
		
<a class="item" data-title="Change the default StorageClass" href="../../administer-cluster/change-default-storage-class/index.html"></a>

		
	
		
		
<a class="item" data-title="Cluster Management" href="../../../admin/cluster-management/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure Multiple Schedulers" href="../../administer-cluster/configure-multiple-schedulers/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure Out Of Resource Handling" href="../../administer-cluster/reserve-compute-resources/out-of-resource.md"></a>

		
	
		
		
<a class="item" data-title="Configure Quotas for API Objects" href="../../administer-cluster/quota-api-object/index.html"></a>

		
	
		
		
<a class="item" data-title="Control CPU Management Policies on the Node" href="../../administer-cluster/cpu-management-policies/index.html"></a>

		
	
		
		
<a class="item" data-title="Customizing DNS Service" href="../../administer-cluster/dns-custom-nameservers/index.html"></a>

		
	
		
		
<a class="item" data-title="Debugging DNS Resolution" href="../../administer-cluster/dns-debugging-resolution/index.html"></a>

		
	
		
		
<a class="item" data-title="Declare Network Policy" href="../declare-network-policy/index.html"></a>

		
	
		
		
<a class="item" data-title="Developing Cloud Controller Manager" href="../../administer-cluster/developing-cloud-controller-manager.md"></a>

		
	
		
		
<a class="item" data-title="Encrypting Secret Data at Rest" href="../../administer-cluster/encrypt-data.1"></a>

		
	
		
		
<a class="item" data-title="Guaranteed Scheduling For Critical Add-On Pods" href="../../administer-cluster/guaranteed-scheduling-critical-addon-pods/index.html"></a>

		
	
		
		
<a class="item" data-title="IP Masquerade Agent User Guide" href="../../administer-cluster/ip-masq-agent/index.html"></a>

		
	
		
		
<a class="item" data-title="Kubernetes Cloud Controller Manager" href="../../administer-cluster/running-cloud-controller.md"></a>

		
	
		
		
<a class="item" data-title="Limit Storage Consumption" href="../../administer-cluster/limit-storage-consumption/index.html"></a>

		
	
		
		
<a class="item" data-title="Namespaces Walkthrough" href="../../administer-cluster/namespaces-walkthrough/index.html"></a>

		
	
		
		
<a class="item" data-title="Operating etcd clusters for Kubernetes" href="../../administer-cluster/configure-upgrade-etcd/index.html"></a>

		
	
		
		
<a class="item" data-title="Reconfigure a Node&#39;s Kubelet in a Live Cluster" href="../../administer-cluster/reconfigure-kubelet.1"></a>

		
	
		
		
<a class="item" data-title="Reserve Compute Resources for System Daemons" href="../../administer-cluster/reserve-compute-resources/index.html"></a>

		
	
		
		
<a class="item" data-title="Safely Drain a Node while Respecting Application SLOs" href="../../administer-cluster/safely-drain-node/index.html"></a>

		
	
		
		
<a class="item" data-title="Securing a Cluster" href="../../administer-cluster/securing-a-cluster/index.html"></a>

		
	
		
		
<a class="item" data-title="Set Kubelet parameters via a config file" href="../../administer-cluster/kubelet-config-file.1"></a>

		
	
		
		
<a class="item" data-title="Set up High-Availability Kubernetes Masters" href="../../administer-cluster/highly-available-master/index.html"></a>

		
	
		
		
<a class="item" data-title="Set up a Highly Availabile etcd Cluster With kubeadm" href="../../administer-cluster/setup-ha-etcd-with-kubeadm/index.html"></a>

		
	
		
		
<a class="item" data-title="Share a Cluster with Namespaces" href="../../../admin/namespaces"></a>

		
	
		
		
<a class="item" data-title="Static Pods" href="../../../concepts/cluster-administration/static-pod/index.html"></a>

		
	
		
		
<a class="item" data-title="Storage Object in Use Protection" href="../../administer-cluster/storage-object-in-use-protection/index.html"></a>

		
	
		
		
<a class="item" data-title="Using CoreDNS for Service Discovery" href="../../administer-cluster/coredns/index.html"></a>

		
	
		
		
<a class="item" data-title="Using a KMS provider for data encryption" href="../../administer-cluster/kms-provider/index.html"></a>

		
	
		
		
<a class="item" data-title="Using sysctls in a Kubernetes Cluster" href="../../../concepts/cluster-administration/sysctl-cluster/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Inject Data Into Applications">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Define a Command and Arguments for a Container" href="../../../user-guide/containers/index.html"></a>

		
	
		
		
<a class="item" data-title="Define Environment Variables for a Container" href="../../inject-data-application/define-environment-variable-container/index.html"></a>

		
	
		
		
<a class="item" data-title="Expose Pod Information to Containers Through Environment Variables" href="../environment-variable-expose-pod-information/index.html"></a>

		
	
		
		
<a class="item" data-title="Expose Pod Information to Containers Through Files" href="../../inject-data-application/downward-api-volume-expose-pod-information/index.html"></a>

		
	
		
		
<a class="item" data-title="Distribute Credentials Securely Using Secrets" href="../../inject-data-application/distribute-credentials-secure/index.html"></a>

		
	
		
		
<a class="item" data-title="Inject Information into Pods Using a PodPreset" href="../../inject-data-application/podpreset.1"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Run Applications">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Run a Stateless Application Using a Deployment" href="../../../user-guide/simple-nginx"></a>

		
	
		
		
<a class="item" data-title="Run a Single-Instance Stateful Application" href="../../../tutorials/stateful-application/run-stateful-application/index.html"></a>

		
	
		
		
<a class="item" data-title="Run a Replicated Stateful Application" href="../../run-application/run-replicated-stateful-application/index.html"></a>

		
	
		
		
<a class="item" data-title="Update API Objects in Place Using kubectl patch" href="../../run-application/update-api-object-kubectl-patch/index.html"></a>

		
	
		
		
<a class="item" data-title="Scale a StatefulSet" href="../../run-application/scale-stateful-set/index.html"></a>

		
	
		
		
<a class="item" data-title="Delete a StatefulSet" href="../../manage-stateful-set/delete-pods/index.html"></a>

		
	
		
		
<a class="item" data-title="Force Delete StatefulSet Pods" href="../../run-application/force-delete-stateful-set-pod/index.html"></a>

		
	
		
		
<a class="item" data-title="Perform Rolling Update Using a Replication Controller" href="../../run-application/rolling-update-replication-controller/index.html"></a>

		
	
		
		
<a class="item" data-title="Horizontal Pod Autoscaler" href="../../run-application/horizontal-pod-autoscale/index.html"></a>

		
	
		
		
<a class="item" data-title="Horizontal Pod Autoscaler Walkthrough" href="../../run-application/horizontal-pod-autoscale-walkthrough/index.html"></a>

		
	
		
		
<a class="item" data-title="Specifying a Disruption Budget for your Application" href="../configure-pod-disruption-budget/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Run Jobs">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Running automated tasks with cron jobs" href="../../job/automated-tasks-with-cron-jobs.1"></a>

		
	
		
		
<a class="item" data-title="Parallel Processing using Expansions" href="../../job/parallel-processing-expansion/index.html"></a>

		
	
		
		
<a class="item" data-title="Coarse Parallel Processing Using a Work Queue" href="../../job/coarse-parallel-processing-work-queue/index.html"></a>

		
	
		
		
<a class="item" data-title="Fine Parallel Processing Using a Work Queue" href="../../job/fine-parallel-processing-work-queue/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Access Applications in a Cluster">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Web UI (Dashboard)" href="../../web-ui-dashboard/index.html"></a>

		
	
		
		
<a class="item" data-title="Accessing Clusters" href="../../../concepts/cluster-administration/access-cluster/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure Access to Multiple Clusters" href="../../access-application-cluster/authenticate-across-clusters-kubeconfig/index.html"></a>

		
	
		
		
<a class="item" data-title="Use Port Forwarding to Access Applications in a Cluster" href="../../access-application-cluster/port-forward-access-application-cluster/index.html"></a>

		
	
		
		
<a class="item" data-title="Provide Load-Balanced Access to an Application in a Cluster" href="../../access-application-cluster/load-balance-access-application-cluster/index.html"></a>

		
	
		
		
<a class="item" data-title="Use a Service to Access an Application in a Cluster" href="../../access-application-cluster/service-access-application-cluster.1"></a>

		
	
		
		
<a class="item" data-title="Connect a Front End to a Back End Using a Service" href="../../access-application-cluster/connecting-frontend-backend/index.html"></a>

		
	
		
		
<a class="item" data-title="Create an External Load Balancer" href="../../../user-guide/load-balancer"></a>

		
	
		
		
<a class="item" data-title="Configure Your Cloud Provider&#39;s Firewalls" href="../../access-application-cluster/configure-cloud-provider-firewall/index.html"></a>

		
	
		
		
<a class="item" data-title="List All Container Images Running in a Cluster" href="../../access-application-cluster/list-all-running-container-images/index.html"></a>

		
	
		
		
<a class="item" data-title="Communicate Between Containers in the Same Pod Using a Shared Volume" href="../../access-application-cluster/communicate-containers-same-pod-shared-volume/index.html"></a>

		
	
		
		
<a class="item" data-title="Configure DNS for a Cluster" href="../../access-application-cluster/configure-dns-cluster/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Monitor, Log, and Debug">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Application Introspection and Debugging" href="../../debug-application-cluster/debug-application-introspection/index.html"></a>

		
	
		
		
<a class="item" data-title="Auditing" href="../../debug-application-cluster/audit/index.html"></a>

		
	
		
		
<a class="item" data-title="Core metrics pipeline" href="../../debug-application-cluster/core-metrics-pipeline/index.html"></a>

		
	
		
		
<a class="item" data-title="Debug Init Containers" href="../../debug-application-cluster/debug-init-containers/index.html"></a>

		
	
		
		
<a class="item" data-title="Debug Pods and Replication Controllers" href="../../debug-application-cluster/debug-pod-replication-controller/index.html"></a>

		
	
		
		
<a class="item" data-title="Debug Services" href="../../../user-guide/debugging-services"></a>

		
	
		
		
<a class="item" data-title="Debug a StatefulSet" href="../../manage-stateful-set/debugging-a-statefulset/index.html"></a>

		
	
		
		
<a class="item" data-title="Debugging Kubernetes nodes with crictl" href="../../debug-application-cluster/crictl/index.html"></a>

		
	
		
		
<a class="item" data-title="Determine the Reason for Pod Failure" href="../../debug-application-cluster/determine-reason-pod-failure/index.html"></a>

		
	
		
		
<a class="item" data-title="Developing and debugging services locally" href="../../debug-application-cluster/local-debugging/index.html"></a>

		
	
		
		
<a class="item" data-title="Events in Stackdriver" href="../../debug-application-cluster/events-stackdriver/index.html"></a>

		
	
		
		
<a class="item" data-title="Get a Shell to a Running Container" href="../../debug-application-cluster/get-shell-running-container/index.html"></a>

		
	
		
		
<a class="item" data-title="Logging Using Elasticsearch and Kibana" href="../../../user-guide/logging/elasticsearch.1"></a>

		
	
		
		
<a class="item" data-title="Logging Using Stackdriver" href="../../../user-guide/logging/stackdriver.1"></a>

		
	
		
		
<a class="item" data-title="Monitor Node Health" href="../../debug-application-cluster/monitor-node-health/index.html"></a>

		
	
		
		
<a class="item" data-title="Tools for Monitoring Compute, Storage, and Network Resources" href="../../debug-application-cluster/resource-usage-monitoring/index.html"></a>

		
	
		
		
<a class="item" data-title="Troubleshoot Applications" href="../../debug-application-cluster/debug-application.1"></a>

		
	
		
		
<a class="item" data-title="Troubleshoot Clusters" href="../../../admin/cluster-troubleshooting.1"></a>

		
	
		
		
<a class="item" data-title="Troubleshooting" href="../../../troubleshooting/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Extend Kubernetes">
		<div class="container">
		
		
	
	
		
		
	<div class="item" data-title="Use Custom Resources">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Extend the Kubernetes API with CustomResourceDefinitions" href="../../access-kubernetes-api/extend-api-custom-resource-definitions/index.html"></a>

		
	
		
		
<a class="item" data-title="Versions of CustomResourceDefinitions" href="../../access-kubernetes-api/custom-resources/custom-resource-definition-versioning/index.html"></a>

		
	
		
		
<a class="item" data-title="Migrate a ThirdPartyResource to CustomResourceDefinition" href="../../access-kubernetes-api/migrate-third-party-resource/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
<a class="item" data-title="Configure the aggregation layer" href="../../access-kubernetes-api/configure-aggregation-layer/index.html"></a>

		
	
		
		
<a class="item" data-title="Setup an extension API server" href="../../access-kubernetes-api/setup-extension-api-server/index.html"></a>

		
	
		
		
<a class="item" data-title="Use an HTTP Proxy to Access the Kubernetes API" href="../../access-kubernetes-api/http-proxy-access-api.1"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="TLS">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Certificate Rotation" href="../../tls/certificate-rotation/index.html"></a>

		
	
		
		
<a class="item" data-title="Manage TLS Certificates in a Cluster" href="../../tls/managing-tls-in-a-cluster.1"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Federation - Run an App on Multiple Clusters">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Cross-cluster Service Discovery using Federated Services" href="../../../concepts/cluster-administration/federation-service-discovery/index.html"></a>

		
	
		
		
<a class="item" data-title="Set up Cluster Federation with Kubefed" href="../../../tutorials/federation/set-up-cluster-federation-kubefed/index.html"></a>

		
	
		
		
<a class="item" data-title="Set up CoreDNS as DNS provider for Cluster Federation" href="../../federation/set-up-coredns-provider-federation/index.html"></a>

		
	
		
		
<a class="item" data-title="Set up placement policies in Federation" href="../../federation/set-up-placement-policies-federation/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Manage Cluster Daemons">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Perform a Rolling Update on a DaemonSet" href="../../manage-daemon/update-daemon-set/index.html"></a>

		
	
		
		
<a class="item" data-title="Performing a Rollback on a DaemonSet" href="../../manage-daemon/rollback-daemon-set/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Install Service Catalog">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Install Service Catalog using Helm" href="../../service-catalog/install-service-catalog-using-helm/index.html"></a>

		
	
		
		
<a class="item" data-title="Install Service Catalog using SC" href="../../service-catalog/install-service-catalog-using-sc/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Federation - Run an App on Multiple Clusters">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Federated Cluster" href="../../administer-federation/cluster/index.html"></a>

		
	
		
		
<a class="item" data-title="Federated ConfigMap" href="../../administer-federation/configmap/index.html"></a>

		
	
		
		
<a class="item" data-title="Federated DaemonSet" href="../../administer-federation/daemonset/index.html"></a>

		
	
		
		
<a class="item" data-title="Federated Deployment" href="../../administer-federation/deployment/index.html"></a>

		
	
		
		
<a class="item" data-title="Federated Events" href="../../administer-federation/events/index.html"></a>

		
	
		
		
<a class="item" data-title="Federated Horizontal Pod Autoscalers (HPA)" href="../../administer-federation/hpa/index.html"></a>

		
	
		
		
<a class="item" data-title="Federated Ingress" href="../../administer-federation/ingress/index.html"></a>

		
	
		
		
<a class="item" data-title="Federated Jobs" href="../../administer-federation/job/index.html"></a>

		
	
		
		
<a class="item" data-title="Federated Namespaces" href="../../administer-federation/namespaces/index.html"></a>

		
	
		
		
<a class="item" data-title="Federated ReplicaSets" href="../../administer-federation/replicaset/index.html"></a>

		
	
		
		
<a class="item" data-title="Federated Secrets" href="../../administer-federation/secret/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
<a class="item" data-title="Extend kubectl with plugins" href="../../extend-kubectl/kubectl-plugins/index.html"></a>

		
	
		
		
<a class="item" data-title="Manage HugePages" href="../../manage-hugepages/scheduling-hugepages/index.html"></a>

		
	
		
		
<a class="item" data-title="Schedule GPUs" href="../../manage-gpus/scheduling-gpus/index.html"></a>

		
	






     </div> 
    <button class="push-menu-close-button" onclick="kub.toggleToc()"></button>
</div> 

			<div id="docsContent">
				
<p><a href="../../../editdocs#docs/tasks/configure-pod-container/configure-pod-configmap.md" id="editPageButton">Edit This Page</a></p>

<h1>Configure a Pod to Use a ConfigMap</h1>




<p>ConfigMaps allow you to decouple configuration artifacts from image content to keep containerized applications portable. This page provides a series of usage examples demonstrating how to create ConfigMaps and configure Pods using data stored in ConfigMaps.</p>











<ul id="markdown-toc">










<li><a href="index.html#before-you-begin">Before you begin</a></li>












<li><a href="index.html#create-a-configmap">Create a ConfigMap</a></li>




<li><a href="index.html#define-pod-environment-variables-using-configmap-data">Define Pod environment variables using ConfigMap data</a></li>




<li><a href="index.html#configure-all-key-value-pairs-in-a-configmap-as-pod-environment-variables">Configure all key-value pairs in a ConfigMap as Pod environment variables</a></li>




<li><a href="index.html#use-configmap-defined-environment-variables-in-pod-commands">Use ConfigMap-defined environment variables in Pod commands</a></li>




<li><a href="index.html#add-configmap-data-to-a-volume">Add ConfigMap data to a Volume</a></li>












<li><a href="index.html#understanding-configmaps-and-pods">Understanding ConfigMaps and Pods</a></li>




















<li><a href="index.html#what-s-next">What's next</a></li>



</ul>



<h2 id="before-you-begin">Before you begin</h2>
<p>You need to have a Kubernetes cluster, and the kubectl command-line tool must
be configured to communicate with your cluster. If you do not already have a
cluster, you can create one by using
<a href="../../../getting-started-guides/minikube">Minikube</a>,
or you can use one of these Kubernetes playgrounds:</p>

<ul>
<li><a href="https://www.katacoda.com/courses/kubernetes/playground" target="_blank">Katacoda</a></li>
<li><a href="http://labs.play-with-k8s.com/" target="_blank">Play with Kubernetes</a></li>
</ul>
 

<p>To check the version, enter <code>kubectl version</code>.</p>




<h2 id="create-a-configmap">Create a ConfigMap</h2>

<p>Use the <code>kubectl create configmap</code> command to create configmaps from <a href="index.html#create-configmaps-from-directories">directories</a>, <a href="index.html#create-configmaps-from-files">files</a>, or <a href="index.html#create-configmaps-from-literal-values">literal values</a>:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl create configmap &lt;map-name&gt; &lt;data-source&gt;</code></pre></div>
<p>where &lt;map-name&gt; is the name you want to assign to the ConfigMap and &lt;data-source&gt; is the directory, file, or literal value to draw the data from.</p>

<p>The data source corresponds to a key-value pair in the ConfigMap, where</p>

<ul>
<li>key = the file name or the key you provided on the command line, and</li>
<li>value = the file contents or the literal value you provided on the command line.</li>
</ul>

<p>You can use <a href="../../../reference/generated/kubectl/kubectl-commands/index.html#describe"><code>kubectl describe</code></a> or
<a href="../../../reference/generated/kubectl/kubectl-commands/index.html#get"><code>kubectl get</code></a> to retrieve information
about a ConfigMap.</p>

<h3 id="create-configmaps-from-directories">Create ConfigMaps from directories</h3>

<p>You can use <code>kubectl create configmap</code> to create a ConfigMap from multiple files in the same directory.</p>

<p>For example:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">mkdir -p configure-pod-container/configmap/kubectl/
wget https://k8s.io/docs/tasks/configure-pod-container/configmap/kubectl/game.properties -O configure-pod-container/configmap/kubectl/game.properties
wget https://k8s.io/docs/tasks/configure-pod-container/configmap/kubectl/ui.properties -O configure-pod-container/configmap/kubectl/ui.properties
kubectl create configmap game-config --from-file<span style="color:#666">=</span>configure-pod-container/configmap/kubectl/</code></pre></div>
<p>combines the contents of the <code>configure-pod-container/configmap/kubectl/</code> directory</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">ls configure-pod-container/configmap/kubectl/
game.properties
ui.properties</code></pre></div>
<p>into the following ConfigMap:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl describe configmaps game-config
Name:           game-config
Namespace:      default
Labels:         &lt;none&gt;
Annotations:    &lt;none&gt;

<span style="color:#b8860b">Data</span>
<span style="color:#666">====</span>
game.properties:        <span style="color:#666">158</span> bytes
ui.properties:          <span style="color:#666">83</span> bytes</code></pre></div>
<p>The <code>game.properties</code> and <code>ui.properties</code> files in the <code>configure-pod-container/configmap/kubectl/</code> directory are represented in the <code>data</code> section of the ConfigMap.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl get configmaps game-config -o yaml</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>data:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>game.properties:<span style="color:#bbb"> </span><span style="color:#b44;font-style:italic">|
</span><span style="color:#b44;font-style:italic">    enemies=aliens
</span><span style="color:#b44;font-style:italic">    lives=3
</span><span style="color:#b44;font-style:italic">    enemies.cheat=true
</span><span style="color:#b44;font-style:italic">    enemies.cheat.level=noGoodRotten
</span><span style="color:#b44;font-style:italic">    secret.code.passphrase=UUDDLRLRBABAS
</span><span style="color:#b44;font-style:italic">    secret.code.allowed=true
</span><span style="color:#b44;font-style:italic">    secret.code.lives=30</span><span style="color:#bbb">
</span><span style="color:#bbb">  </span>ui.properties:<span style="color:#bbb"> </span><span style="color:#b44;font-style:italic">|
</span><span style="color:#b44;font-style:italic">    color.good=purple
</span><span style="color:#b44;font-style:italic">    color.bad=yellow
</span><span style="color:#b44;font-style:italic">    allow.textmode=true
</span><span style="color:#b44;font-style:italic">    how.nice.to.look=fairlyNice</span><span style="color:#bbb">
</span><span style="color:#bbb"></span>kind:<span style="color:#bbb"> </span>ConfigMap<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>creationTimestamp:<span style="color:#bbb"> </span>2016-02-18T18:52:05Z<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>game-config<span style="color:#bbb">
</span><span style="color:#bbb">  </span>namespace:<span style="color:#bbb"> </span>default<span style="color:#bbb">
</span><span style="color:#bbb">  </span>resourceVersion:<span style="color:#bbb"> </span><span style="color:#b44">&#34;516&#34;</span><span style="color:#bbb">
</span><span style="color:#bbb">  </span>selfLink:<span style="color:#bbb"> </span>/api/v1/namespaces/default/configmaps/game-config<span style="color:#bbb">
</span><span style="color:#bbb">  </span>uid:<span style="color:#bbb"> </span>b4952dc3-d670-<span style="color:#666">11e5</span>-8cd0-68f728db1985</code></pre></div>
<h3 id="create-configmaps-from-files">Create ConfigMaps from files</h3>

<p>You can use <code>kubectl create configmap</code> to create a ConfigMap from an individual file, or from multiple files.</p>

<p>For example,</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl create configmap game-config-2 --from-file<span style="color:#666">=</span>configure-pod-container/configmap/kubectl/game.properties</code></pre></div>
<p>would produce the following ConfigMap:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl describe configmaps game-config-2
Name:           game-config-2
Namespace:      default
Labels:         &lt;none&gt;
Annotations:    &lt;none&gt;

<span style="color:#b8860b">Data</span>
<span style="color:#666">====</span>
game.properties:        <span style="color:#666">158</span> bytes</code></pre></div>
<p>You can pass in the  <code>--from-file</code> argument multiple times to create a ConfigMap from multiple data sources.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl create configmap game-config-2 --from-file<span style="color:#666">=</span>configure-pod-container/configmap/kubectl/game.properties --from-file<span style="color:#666">=</span>configure-pod-container/configmap/kubectl/ui.properties</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl describe configmaps game-config-2
Name:           game-config-2
Namespace:      default
Labels:         &lt;none&gt;
Annotations:    &lt;none&gt;

<span style="color:#b8860b">Data</span>
<span style="color:#666">====</span>
game.properties:        <span style="color:#666">158</span> bytes
ui.properties:          <span style="color:#666">83</span> bytes</code></pre></div>
<p>Use the option <code>--from-env-file</code> to create a ConfigMap from an env-file, for example:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#080;font-style:italic"># Env-files contain a list of environment variables.
</span><span style="color:#080;font-style:italic"># These syntax rules apply:
</span><span style="color:#080;font-style:italic">#   Each line in an env file has to be in VAR=VAL format.
</span><span style="color:#080;font-style:italic">#   Lines beginning with # (i.e. comments) are ignored.
</span><span style="color:#080;font-style:italic">#   Blank lines are ignored.
</span><span style="color:#080;font-style:italic">#   There is no special handling of quotation marks (i.e. they will be part of the ConfigMap value)).
</span><span style="color:#080;font-style:italic"></span>
wget https://k8s.io/docs/tasks/configure-pod-container/configmap/kubectl/game-env-file.properties -O configure-pod-container/configmap/kubectl/game-env-file.properties
cat configure-pod-container/configmap/kubectl/game-env-file.properties
<span style="color:#b8860b">enemies</span><span style="color:#666">=</span>aliens
<span style="color:#b8860b">lives</span><span style="color:#666">=</span><span style="color:#666">3</span>
<span style="color:#b8860b">allowed</span><span style="color:#666">=</span><span style="color:#b44">&#34;true&#34;</span>

# This comment and the empty line above it are ignored</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl create configmap game-config-env-file <span style="color:#b62;font-weight:bold">\
</span><span style="color:#b62;font-weight:bold"></span>        --from-env-file<span style="color:#666">=</span>configure-pod-container/configmap/kubectl/game-env-file.properties</code></pre></div>
<p>would produce the following ConfigMap:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl get configmap game-config-env-file -o yaml</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>data:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>allowed:<span style="color:#bbb"> </span><span style="color:#b44">&#39;&#34;true&#34;&#39;</span><span style="color:#bbb">
</span><span style="color:#bbb">  </span>enemies:<span style="color:#bbb"> </span>aliens<span style="color:#bbb">
</span><span style="color:#bbb">  </span>lives:<span style="color:#bbb"> </span><span style="color:#b44">&#34;3&#34;</span><span style="color:#bbb">
</span><span style="color:#bbb"></span>kind:<span style="color:#bbb"> </span>ConfigMap<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>creationTimestamp:<span style="color:#bbb"> </span>2017-12-27T18:36:28Z<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>game-config-env-file<span style="color:#bbb">
</span><span style="color:#bbb">  </span>namespace:<span style="color:#bbb"> </span>default<span style="color:#bbb">
</span><span style="color:#bbb">  </span>resourceVersion:<span style="color:#bbb"> </span><span style="color:#b44">&#34;809965&#34;</span><span style="color:#bbb">
</span><span style="color:#bbb">  </span>selfLink:<span style="color:#bbb"> </span>/api/v1/namespaces/default/configmaps/game-config-env-file<span style="color:#bbb">
</span><span style="color:#bbb">  </span>uid:<span style="color:#bbb"> </span>d9d1ca5b-eb34-<span style="color:#666">11e7</span>-887b-42010a8002b8</code></pre></div>
<p>When passing <code>--from-env-file</code> multiple times to create a ConfigMap from multiple data sources, only the last env-file is used:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">wget https://k8s.io/docs/tasks/configure-pod-container/configmap/kubectl/ui-env-file.properties -O configure-pod-container/configmap/kubectl/ui-env-file.properties
kubectl create configmap config-multi-env-files <span style="color:#b62;font-weight:bold">\
</span><span style="color:#b62;font-weight:bold"></span>        --from-env-file<span style="color:#666">=</span>configure-pod-container/configmap/kubectl/game-env-file.properties <span style="color:#b62;font-weight:bold">\
</span><span style="color:#b62;font-weight:bold"></span>        --from-env-file<span style="color:#666">=</span>configure-pod-container/configmap/kubectl/ui-env-file.properties</code></pre></div>
<p>would produce the following ConfigMap:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl get configmap config-multi-env-files -o yaml</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>data:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>color:<span style="color:#bbb"> </span>purple<span style="color:#bbb">
</span><span style="color:#bbb">  </span>how:<span style="color:#bbb"> </span>fairlyNice<span style="color:#bbb">
</span><span style="color:#bbb">  </span>textmode:<span style="color:#bbb"> </span><span style="color:#b44">&#34;true&#34;</span><span style="color:#bbb">
</span><span style="color:#bbb"></span>kind:<span style="color:#bbb"> </span>ConfigMap<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>creationTimestamp:<span style="color:#bbb"> </span>2017-12-27T18:38:34Z<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>config-multi-env-files<span style="color:#bbb">
</span><span style="color:#bbb">  </span>namespace:<span style="color:#bbb"> </span>default<span style="color:#bbb">
</span><span style="color:#bbb">  </span>resourceVersion:<span style="color:#bbb"> </span><span style="color:#b44">&#34;810136&#34;</span><span style="color:#bbb">
</span><span style="color:#bbb">  </span>selfLink:<span style="color:#bbb"> </span>/api/v1/namespaces/default/configmaps/config-multi-env-files<span style="color:#bbb">
</span><span style="color:#bbb">  </span>uid:<span style="color:#bbb"> </span>252c4572-eb35-<span style="color:#666">11e7</span>-887b-42010a8002b8</code></pre></div>
<h4 id="define-the-key-to-use-when-creating-a-configmap-from-a-file">Define the key to use when creating a ConfigMap from a file</h4>

<p>You can define a key other than the file name to use in the <code>data</code> section of your ConfigMap when using the <code>--from-file</code> argument:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl create configmap game-config-3 --from-file<span style="color:#666">=</span>&lt;my-key-name&gt;<span style="color:#666">=</span>&lt;path-to-file&gt;</code></pre></div>
<p>where <code>&lt;my-key-name&gt;</code> is the key you want to use in the ConfigMap and <code>&lt;path-to-file&gt;</code> is the location of the data source file you want the key to represent.</p>

<p>For example:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl create configmap game-config-3 --from-file<span style="color:#666">=</span>game-special-key<span style="color:#666">=</span>configure-pod-container/configmap/kubectl/game.properties

kubectl get configmaps game-config-3 -o yaml</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>data:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>game-special-key:<span style="color:#bbb"> </span><span style="color:#b44;font-style:italic">|
</span><span style="color:#b44;font-style:italic">    enemies=aliens
</span><span style="color:#b44;font-style:italic">    lives=3
</span><span style="color:#b44;font-style:italic">    enemies.cheat=true
</span><span style="color:#b44;font-style:italic">    enemies.cheat.level=noGoodRotten
</span><span style="color:#b44;font-style:italic">    secret.code.passphrase=UUDDLRLRBABAS
</span><span style="color:#b44;font-style:italic">    secret.code.allowed=true
</span><span style="color:#b44;font-style:italic">    secret.code.lives=30</span><span style="color:#bbb">
</span><span style="color:#bbb"></span>kind:<span style="color:#bbb"> </span>ConfigMap<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>creationTimestamp:<span style="color:#bbb"> </span>2016-02-18T18:54:22Z<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>game-config-<span style="color:#666">3</span><span style="color:#bbb">
</span><span style="color:#bbb">  </span>namespace:<span style="color:#bbb"> </span>default<span style="color:#bbb">
</span><span style="color:#bbb">  </span>resourceVersion:<span style="color:#bbb"> </span><span style="color:#b44">&#34;530&#34;</span><span style="color:#bbb">
</span><span style="color:#bbb">  </span>selfLink:<span style="color:#bbb"> </span>/api/v1/namespaces/default/configmaps/game-config-<span style="color:#666">3</span><span style="color:#bbb">
</span><span style="color:#bbb">  </span>uid:<span style="color:#bbb"> </span>05f8da22-d671-<span style="color:#666">11e5</span>-8cd0-68f728db1985</code></pre></div>
<h3 id="create-configmaps-from-literal-values">Create ConfigMaps from literal values</h3>

<p>You can use <code>kubectl create configmap</code> with the <code>--from-literal</code> argument to define a literal value from the command line:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl create configmap special-config --from-literal<span style="color:#666">=</span>special.how<span style="color:#666">=</span>very --from-literal<span style="color:#666">=</span>special.type<span style="color:#666">=</span>charm</code></pre></div>
<p>You can pass in multiple key-value pairs. Each pair provided on the command line is represented as a separate entry in the <code>data</code> section of the ConfigMap.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl get configmaps special-config -o yaml</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>data:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>special.how:<span style="color:#bbb"> </span>very<span style="color:#bbb">
</span><span style="color:#bbb">  </span>special.type:<span style="color:#bbb"> </span>charm<span style="color:#bbb">
</span><span style="color:#bbb"></span>kind:<span style="color:#bbb"> </span>ConfigMap<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>creationTimestamp:<span style="color:#bbb"> </span>2016-02-18T19:14:38Z<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>special-config<span style="color:#bbb">
</span><span style="color:#bbb">  </span>namespace:<span style="color:#bbb"> </span>default<span style="color:#bbb">
</span><span style="color:#bbb">  </span>resourceVersion:<span style="color:#bbb"> </span><span style="color:#b44">&#34;651&#34;</span><span style="color:#bbb">
</span><span style="color:#bbb">  </span>selfLink:<span style="color:#bbb"> </span>/api/v1/namespaces/default/configmaps/special-config<span style="color:#bbb">
</span><span style="color:#bbb">  </span>uid:<span style="color:#bbb"> </span>dadce046-d673-<span style="color:#666">11e5</span>-8cd0-68f728db1985</code></pre></div>
<h2 id="define-pod-environment-variables-using-configmap-data">Define Pod environment variables using ConfigMap data</h2>

<h3 id="define-a-pod-environment-variable-with-data-from-a-single-configmap">Define a Pod environment variable with data from a single ConfigMap</h3>

<ol>
<li>Define an environment variable as a key-value pair in a ConfigMap:</li>
</ol>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">   kubectl create configmap special-config --from-literal<span style="color:#666">=</span>special.how<span style="color:#666">=</span>very </code></pre></div>
<ol>
<li>Assign the <code>special.how</code> value defined in the ConfigMap to the <code>SPECIAL_LEVEL_KEY</code> environment variable in the Pod specification.</li>
</ol>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">   kubectl edit pod dapi-test-pod</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#bbb">   </span>apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb">   </span>kind:<span style="color:#bbb"> </span>Pod<span style="color:#bbb">
</span><span style="color:#bbb">   </span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">     </span>name:<span style="color:#bbb"> </span>dapi-test-pod<span style="color:#bbb">
</span><span style="color:#bbb">   </span>spec:<span style="color:#bbb">
</span><span style="color:#bbb">     </span>containers:<span style="color:#bbb">
</span><span style="color:#bbb">       </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>test-container<span style="color:#bbb">
</span><span style="color:#bbb">         </span>image:<span style="color:#bbb"> </span>k8s.gcr.io/busybox<span style="color:#bbb">
</span><span style="color:#bbb">         </span>command:<span style="color:#bbb"> </span>[<span style="color:#bbb"> </span><span style="color:#b44">&#34;/bin/sh&#34;</span>,<span style="color:#bbb"> </span><span style="color:#b44">&#34;-c&#34;</span>,<span style="color:#bbb"> </span><span style="color:#b44">&#34;env&#34;</span><span style="color:#bbb"> </span>]<span style="color:#bbb">
</span><span style="color:#bbb">         </span>env:<span style="color:#bbb">
</span><span style="color:#bbb">           </span><span style="color:#080;font-style:italic"># Define the environment variable</span><span style="color:#bbb">
</span><span style="color:#bbb">           </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>SPECIAL_LEVEL_KEY<span style="color:#bbb">
</span><span style="color:#bbb">             </span>valueFrom:<span style="color:#bbb">
</span><span style="color:#bbb">               </span>configMapKeyRef:<span style="color:#bbb">
</span><span style="color:#bbb">                 </span><span style="color:#080;font-style:italic"># The ConfigMap containing the value you want to assign to SPECIAL_LEVEL_KEY</span><span style="color:#bbb">
</span><span style="color:#bbb">                 </span>name:<span style="color:#bbb"> </span>special-config<span style="color:#bbb">
</span><span style="color:#bbb">                 </span><span style="color:#080;font-style:italic"># Specify the key associated with the value</span><span style="color:#bbb">
</span><span style="color:#bbb">                 </span>key:<span style="color:#bbb"> </span>special.how<span style="color:#bbb">
</span><span style="color:#bbb">     </span>restartPolicy:<span style="color:#bbb"> </span>Never</code></pre></div>
<ol>
<li>Save the changes to the Pod specification. Now, the Pod&rsquo;s output includes <code>SPECIAL_LEVEL_KEY=very</code>.</li>
</ol>

<h3 id="define-pod-environment-variables-with-data-from-multiple-configmaps">Define Pod environment variables with data from multiple ConfigMaps</h3>

<ol>
<li>As with the previous example, create the ConfigMaps first.</li>
</ol>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#bbb">   </span>apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb">   </span>kind:<span style="color:#bbb"> </span>ConfigMap<span style="color:#bbb">
</span><span style="color:#bbb">   </span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">     </span>name:<span style="color:#bbb"> </span>special-config<span style="color:#bbb">
</span><span style="color:#bbb">     </span>namespace:<span style="color:#bbb"> </span>default<span style="color:#bbb">
</span><span style="color:#bbb">   </span>data:<span style="color:#bbb">
</span><span style="color:#bbb">     </span>special.how:<span style="color:#bbb"> </span>very</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#bbb">   </span>apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb">   </span>kind:<span style="color:#bbb"> </span>ConfigMap<span style="color:#bbb">
</span><span style="color:#bbb">   </span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">     </span>name:<span style="color:#bbb"> </span>env-config<span style="color:#bbb">
</span><span style="color:#bbb">     </span>namespace:<span style="color:#bbb"> </span>default<span style="color:#bbb">
</span><span style="color:#bbb">   </span>data:<span style="color:#bbb">
</span><span style="color:#bbb">     </span>log_level:<span style="color:#bbb"> </span>INFO</code></pre></div>
<ol>
<li>Define the environment variables in the Pod specification.</li>
</ol>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#bbb">   </span>apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb">   </span>kind:<span style="color:#bbb"> </span>Pod<span style="color:#bbb">
</span><span style="color:#bbb">   </span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">     </span>name:<span style="color:#bbb"> </span>dapi-test-pod<span style="color:#bbb">
</span><span style="color:#bbb">   </span>spec:<span style="color:#bbb">
</span><span style="color:#bbb">     </span>containers:<span style="color:#bbb">
</span><span style="color:#bbb">       </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>test-container<span style="color:#bbb">
</span><span style="color:#bbb">         </span>image:<span style="color:#bbb"> </span>k8s.gcr.io/busybox<span style="color:#bbb">
</span><span style="color:#bbb">         </span>command:<span style="color:#bbb"> </span>[<span style="color:#bbb"> </span><span style="color:#b44">&#34;/bin/sh&#34;</span>,<span style="color:#bbb"> </span><span style="color:#b44">&#34;-c&#34;</span>,<span style="color:#bbb"> </span><span style="color:#b44">&#34;env&#34;</span><span style="color:#bbb"> </span>]<span style="color:#bbb">
</span><span style="color:#bbb">         </span>env:<span style="color:#bbb">
</span><span style="color:#bbb">           </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>SPECIAL_LEVEL_KEY<span style="color:#bbb">
</span><span style="color:#bbb">             </span>valueFrom:<span style="color:#bbb">
</span><span style="color:#bbb">               </span>configMapKeyRef:<span style="color:#bbb">
</span><span style="color:#bbb">                 </span>name:<span style="color:#bbb"> </span>special-config<span style="color:#bbb">
</span><span style="color:#bbb">                 </span>key:<span style="color:#bbb"> </span>special.how<span style="color:#bbb">
</span><span style="color:#bbb">           </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>LOG_LEVEL<span style="color:#bbb">
</span><span style="color:#bbb">             </span>valueFrom:<span style="color:#bbb">
</span><span style="color:#bbb">               </span>configMapKeyRef:<span style="color:#bbb">
</span><span style="color:#bbb">                 </span>name:<span style="color:#bbb"> </span>env-config<span style="color:#bbb">
</span><span style="color:#bbb">                 </span>key:<span style="color:#bbb"> </span>log_level<span style="color:#bbb">
</span><span style="color:#bbb">     </span>restartPolicy:<span style="color:#bbb"> </span>Never</code></pre></div>
<ol>
<li>Save the changes to the Pod specification. Now, the Pod&rsquo;s output includes <code>SPECIAL_LEVEL_KEY=very</code> and <code>LOG_LEVEL=info</code>.</li>
</ol>

<h2 id="configure-all-key-value-pairs-in-a-configmap-as-pod-environment-variables">Configure all key-value pairs in a ConfigMap as Pod environment variables</h2>

<p><blockquote class="note">
  <div><strong>Note:</strong> This functionality is available to users running Kubernetes v1.6 and later.</div>
</blockquote></p>

<ol>
<li>Create a ConfigMap containing multiple key-value pairs.</li>
</ol>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#bbb">   </span>apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb">   </span>kind:<span style="color:#bbb"> </span>ConfigMap<span style="color:#bbb">
</span><span style="color:#bbb">   </span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">     </span>name:<span style="color:#bbb"> </span>special-config<span style="color:#bbb">
</span><span style="color:#bbb">     </span>namespace:<span style="color:#bbb"> </span>default<span style="color:#bbb">
</span><span style="color:#bbb">   </span>data:<span style="color:#bbb">
</span><span style="color:#bbb">     </span>SPECIAL_LEVEL:<span style="color:#bbb"> </span>very<span style="color:#bbb">
</span><span style="color:#bbb">     </span>SPECIAL_TYPE:<span style="color:#bbb"> </span>charm</code></pre></div>
<ol>
<li>Use <code>envFrom</code> to define all of the ConfigMap&rsquo;s data as Pod environment variables. The key from the ConfigMap becomes the environment variable name in the Pod.
<br /></li>
</ol>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#bbb">   </span>apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb">   </span>kind:<span style="color:#bbb"> </span>Pod<span style="color:#bbb">
</span><span style="color:#bbb">   </span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">     </span>name:<span style="color:#bbb"> </span>dapi-test-pod<span style="color:#bbb">
</span><span style="color:#bbb">   </span>spec:<span style="color:#bbb">
</span><span style="color:#bbb">     </span>containers:<span style="color:#bbb">
</span><span style="color:#bbb">       </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>test-container<span style="color:#bbb">
</span><span style="color:#bbb">         </span>image:<span style="color:#bbb"> </span>k8s.gcr.io/busybox<span style="color:#bbb">
</span><span style="color:#bbb">         </span>command:<span style="color:#bbb"> </span>[<span style="color:#bbb"> </span><span style="color:#b44">&#34;/bin/sh&#34;</span>,<span style="color:#bbb"> </span><span style="color:#b44">&#34;-c&#34;</span>,<span style="color:#bbb"> </span><span style="color:#b44">&#34;env&#34;</span><span style="color:#bbb"> </span>]<span style="color:#bbb">
</span><span style="color:#bbb">         </span>envFrom:<span style="color:#bbb">
</span><span style="color:#bbb">         </span>-<span style="color:#bbb"> </span>configMapRef:<span style="color:#bbb">
</span><span style="color:#bbb">             </span>name:<span style="color:#bbb"> </span>special-config<span style="color:#bbb">
</span><span style="color:#bbb">     </span>restartPolicy:<span style="color:#bbb"> </span>Never</code></pre></div>
<ol>
<li>Save the changes to the Pod specification. Now, the Pod&rsquo;s output includes <code>SPECIAL_LEVEL=very</code> and <code>SPECIAL_TYPE=charm</code>.</li>
</ol>

<h2 id="use-configmap-defined-environment-variables-in-pod-commands">Use ConfigMap-defined environment variables in Pod commands</h2>

<p>You can use ConfigMap-defined environment variables in the <code>command</code> section of the Pod specification using the <code>$(VAR_NAME)</code> Kubernetes substitution syntax.</p>

<p>For example:</p>

<p>The following Pod specification</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>kind:<span style="color:#bbb"> </span>Pod<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>dapi-test-pod<span style="color:#bbb">
</span><span style="color:#bbb"></span>spec:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>containers:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>test-container<span style="color:#bbb">
</span><span style="color:#bbb">      </span>image:<span style="color:#bbb"> </span>k8s.gcr.io/busybox<span style="color:#bbb">
</span><span style="color:#bbb">      </span>command:<span style="color:#bbb"> </span>[<span style="color:#bbb"> </span><span style="color:#b44">&#34;/bin/sh&#34;</span>,<span style="color:#bbb"> </span><span style="color:#b44">&#34;-c&#34;</span>,<span style="color:#bbb"> </span><span style="color:#b44">&#34;echo $(SPECIAL_LEVEL_KEY) $(SPECIAL_TYPE_KEY)&#34;</span><span style="color:#bbb"> </span>]<span style="color:#bbb">
</span><span style="color:#bbb">      </span>env:<span style="color:#bbb">
</span><span style="color:#bbb">        </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>SPECIAL_LEVEL_KEY<span style="color:#bbb">
</span><span style="color:#bbb">          </span>valueFrom:<span style="color:#bbb">
</span><span style="color:#bbb">            </span>configMapKeyRef:<span style="color:#bbb">
</span><span style="color:#bbb">              </span>name:<span style="color:#bbb"> </span>special-config<span style="color:#bbb">
</span><span style="color:#bbb">              </span>key:<span style="color:#bbb"> </span>SPECIAL_LEVEL<span style="color:#bbb">
</span><span style="color:#bbb">        </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>SPECIAL_TYPE_KEY<span style="color:#bbb">
</span><span style="color:#bbb">          </span>valueFrom:<span style="color:#bbb">
</span><span style="color:#bbb">            </span>configMapKeyRef:<span style="color:#bbb">
</span><span style="color:#bbb">              </span>name:<span style="color:#bbb"> </span>special-config<span style="color:#bbb">
</span><span style="color:#bbb">              </span>key:<span style="color:#bbb"> </span>SPECIAL_TYPE<span style="color:#bbb">
</span><span style="color:#bbb">  </span>restartPolicy:<span style="color:#bbb"> </span>Never</code></pre></div>
<p>produces the following output in the <code>test-container</code> container:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">very charm</code></pre></div>
<h2 id="add-configmap-data-to-a-volume">Add ConfigMap data to a Volume</h2>

<p>As explained in <a href="index.html#create-configmaps-from-files">Create ConfigMaps from files</a>, when you create a ConfigMap using <code>--from-file</code>, the filename becomes a key stored in the <code>data</code> section of the ConfigMap. The file contents become the key&rsquo;s value.</p>

<p>The examples in this section refer to a ConfigMap named special-config, shown below.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>kind:<span style="color:#bbb"> </span>ConfigMap<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>special-config<span style="color:#bbb">
</span><span style="color:#bbb">  </span>namespace:<span style="color:#bbb"> </span>default<span style="color:#bbb">
</span><span style="color:#bbb"></span>data:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>special.level:<span style="color:#bbb"> </span>very<span style="color:#bbb">
</span><span style="color:#bbb">  </span>special.type:<span style="color:#bbb"> </span>charm</code></pre></div>
<h3 id="populate-a-volume-with-data-stored-in-a-configmap">Populate a Volume with data stored in a ConfigMap</h3>

<p>Add the ConfigMap name under the <code>volumes</code> section of the Pod specification.
This adds the ConfigMap data to the directory specified as <code>volumeMounts.mountPath</code> (in this case, <code>/etc/config</code>).
The <code>command</code> section references the <code>special.level</code> item stored in the ConfigMap.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>kind:<span style="color:#bbb"> </span>Pod<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>dapi-test-pod<span style="color:#bbb">
</span><span style="color:#bbb"></span>spec:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>containers:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>test-container<span style="color:#bbb">
</span><span style="color:#bbb">      </span>image:<span style="color:#bbb"> </span>k8s.gcr.io/busybox<span style="color:#bbb">
</span><span style="color:#bbb">      </span>command:<span style="color:#bbb"> </span>[<span style="color:#bbb"> </span><span style="color:#b44">&#34;/bin/sh&#34;</span>,<span style="color:#bbb"> </span><span style="color:#b44">&#34;-c&#34;</span>,<span style="color:#bbb"> </span><span style="color:#b44">&#34;ls /etc/config/&#34;</span><span style="color:#bbb"> </span>]<span style="color:#bbb">
</span><span style="color:#bbb">      </span>volumeMounts:<span style="color:#bbb">
</span><span style="color:#bbb">      </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>config-volume<span style="color:#bbb">
</span><span style="color:#bbb">        </span>mountPath:<span style="color:#bbb"> </span>/etc/config<span style="color:#bbb">
</span><span style="color:#bbb">  </span>volumes:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>config-volume<span style="color:#bbb">
</span><span style="color:#bbb">      </span>configMap:<span style="color:#bbb">
</span><span style="color:#bbb">        </span><span style="color:#080;font-style:italic"># Provide the name of the ConfigMap containing the files you want</span><span style="color:#bbb">
</span><span style="color:#bbb">        </span><span style="color:#080;font-style:italic"># to add to the container</span><span style="color:#bbb">
</span><span style="color:#bbb">        </span>name:<span style="color:#bbb"> </span>special-config<span style="color:#bbb">
</span><span style="color:#bbb">  </span>restartPolicy:<span style="color:#bbb"> </span>Never</code></pre></div>
<p>When the pod runs, the command (<code>&quot;ls /etc/config/&quot;</code>) produces the output below:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">special.level
special.type</code></pre></div>
<blockquote class="caution">
  <div><strong>Caution:</strong> If there are some files in the <code>/etc/config/</code> directory, they will be deleted.</div>
</blockquote>

<h3 id="add-configmap-data-to-a-specific-path-in-the-volume">Add ConfigMap data to a specific path in the Volume</h3>

<p>Use the <code>path</code> field to specify the desired file path for specific ConfigMap items.
In this case, the <code>special.level</code> item will be mounted in the <code>config-volume</code> volume at <code>/etc/config/keys</code>.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>kind:<span style="color:#bbb"> </span>Pod<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>dapi-test-pod<span style="color:#bbb">
</span><span style="color:#bbb"></span>spec:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>containers:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>test-container<span style="color:#bbb">
</span><span style="color:#bbb">      </span>image:<span style="color:#bbb"> </span>k8s.gcr.io/busybox<span style="color:#bbb">
</span><span style="color:#bbb">      </span>command:<span style="color:#bbb"> </span>[<span style="color:#bbb"> </span><span style="color:#b44">&#34;/bin/sh&#34;</span>,<span style="color:#b44">&#34;-c&#34;</span>,<span style="color:#b44">&#34;cat /etc/config/keys&#34;</span><span style="color:#bbb"> </span>]<span style="color:#bbb">
</span><span style="color:#bbb">      </span>volumeMounts:<span style="color:#bbb">
</span><span style="color:#bbb">      </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>config-volume<span style="color:#bbb">
</span><span style="color:#bbb">        </span>mountPath:<span style="color:#bbb"> </span>/etc/config<span style="color:#bbb">
</span><span style="color:#bbb">  </span>volumes:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>config-volume<span style="color:#bbb">
</span><span style="color:#bbb">      </span>configMap:<span style="color:#bbb">
</span><span style="color:#bbb">        </span>name:<span style="color:#bbb"> </span>special-config<span style="color:#bbb">
</span><span style="color:#bbb">        </span>items:<span style="color:#bbb">
</span><span style="color:#bbb">        </span>-<span style="color:#bbb"> </span>key:<span style="color:#bbb"> </span>special.level<span style="color:#bbb">
</span><span style="color:#bbb">          </span>path:<span style="color:#bbb"> </span>keys<span style="color:#bbb">
</span><span style="color:#bbb">  </span>restartPolicy:<span style="color:#bbb"> </span>Never</code></pre></div>
<p>When the pod runs, the command (<code>&quot;cat /etc/config/keys&quot;</code>) produces the output below:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">very</code></pre></div>
<h3 id="project-keys-to-specific-paths-and-file-permissions">Project keys to specific paths and file permissions</h3>

<p>You can project keys to specific paths and specific permissions on a per-file
basis. The <a href="../../../user-guide/secrets.1#using-secrets-as-files-from-a-pod">Secrets</a> user guide explains the syntax.</p>

<h3 id="mounted-configmaps-are-updated-automatically">Mounted ConfigMaps are updated automatically</h3>

<p>When a ConfigMap already being consumed in a volume is updated, projected keys are eventually updated as well. Kubelet is checking whether the mounted ConfigMap is fresh on every periodic sync. However, it is using its local ttl-based cache for getting the current value of the ConfigMap. As a result, the total delay from the moment when the ConfigMap is updated to the moment when new keys are projected to the pod can be as long as kubelet sync period + ttl of ConfigMaps cache in kubelet.</p>

<blockquote class="note">
  <div><strong>Note:</strong> A container using a ConfigMap as a
<a href="../../../concepts/storage/volumes.1#using-subpath">subPath</a> volume will not receive
ConfigMap updates.</div>
</blockquote>




<h2 id="understanding-configmaps-and-pods">Understanding ConfigMaps and Pods</h2>

<p>The ConfigMap API resource stores configuration data as key-value pairs. The data can be consumed in pods or provide the configurations for system components such as controllers. ConfigMap is similar to <a href="../../../user-guide/secrets.1">Secrets</a>, but provides a means of working with strings that don&rsquo;t contain sensitive information. Users and system components alike can store configuration data in ConfigMap.</p>

<blockquote class="note">
  <div><strong>Note:</strong> ConfigMaps should reference properties files, not replace them. Think of the ConfigMap as representing something similar to the Linux <code>/etc</code> directory and its contents. For example, if you create a <a href="../../../concepts/storage/volumes.1">Kubernetes Volume</a> from a ConfigMap, each data item in the ConfigMap is represented by an individual file in the volume.</div>
</blockquote>

<p>The ConfigMap&rsquo;s <code>data</code> field contains the configuration data. As shown in the example below, this can be simple &ndash; like individual properties defined using <code>--from-literal</code> &ndash; or complex &ndash; like configuration files or JSON blobs defined using <code>--from-file</code>.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">kind:<span style="color:#bbb"> </span>ConfigMap<span style="color:#bbb">
</span><span style="color:#bbb"></span>apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>creationTimestamp:<span style="color:#bbb"> </span>2016-02-18T19:14:38Z<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>example-config<span style="color:#bbb">
</span><span style="color:#bbb">  </span>namespace:<span style="color:#bbb"> </span>default<span style="color:#bbb">
</span><span style="color:#bbb"></span>data:<span style="color:#bbb">
</span><span style="color:#bbb">  </span><span style="color:#080;font-style:italic"># example of a simple property defined using --from-literal</span><span style="color:#bbb">
</span><span style="color:#bbb">  </span>example.property.<span style="color:#666">1</span>:<span style="color:#bbb"> </span>hello<span style="color:#bbb">
</span><span style="color:#bbb">  </span>example.property.<span style="color:#666">2</span>:<span style="color:#bbb"> </span>world<span style="color:#bbb">
</span><span style="color:#bbb">  </span><span style="color:#080;font-style:italic"># example of a complex property defined using --from-file</span><span style="color:#bbb">
</span><span style="color:#bbb">  </span>example.property.file:<span style="color:#bbb"> </span>|-<span style="color:#bbb">
</span><span style="color:#bbb">    </span>property.<span style="color:#666">1</span>=value-<span style="color:#666">1</span><span style="color:#bbb">
</span><span style="color:#bbb">    </span>property.<span style="color:#666">2</span>=value-<span style="color:#666">2</span><span style="color:#bbb">
</span><span style="color:#bbb">    </span>property.<span style="color:#666">3</span>=value-<span style="color:#666">3</span></code></pre></div>
<h3 id="restrictions">Restrictions</h3>

<ol>
<li><p>You must create a ConfigMap before referencing it in a Pod specification (unless you mark the ConfigMap as &ldquo;optional&rdquo;). If you reference a ConfigMap that doesn&rsquo;t exist, the Pod won&rsquo;t start. Likewise, references to keys that don&rsquo;t exist in the ConfigMap will prevent the pod from starting.</p></li>

<li><p>If you use <code>envFrom</code> to define environment variables from ConfigMaps, keys that are considered invalid will be skipped. The pod will be allowed to start, but the invalid names will be recorded in the event log (<code>InvalidVariableNames</code>). The log message lists each skipped key. For example:</p></li>
</ol>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">   kubectl get events
   LASTSEEN FIRSTSEEN COUNT NAME          KIND  SUBOBJECT  TYPE      REASON                            SOURCE                MESSAGE
   0s       0s        <span style="color:#666">1</span>     dapi-test-pod Pod              Warning   InvalidEnvironmentVariableNames   <span style="color:#666">{</span>kubelet, <span style="color:#666">127</span>.0.0.1<span style="color:#666">}</span>  Keys <span style="color:#666">[</span>1badkey, 2alsobad<span style="color:#666">]</span> from the EnvFrom configMap default/myconfig were skipped since they are considered invalid environment variable names.</code></pre></div>
<ol>
<li><p>ConfigMaps reside in a specific <a href="../../../concepts/overview/working-with-objects/namespaces.1">namespace</a>. A ConfigMap can only be referenced by pods residing in the same namespace.</p></li>

<li><p>Kubelet doesn&rsquo;t support the use of ConfigMaps for pods not found on the API server.
This includes pods created via the Kubelet&rsquo;s &ndash;manifest-url flag, &ndash;config flag, or the Kubelet REST API.</p></li>
</ol>

<p><blockquote class="note">
  <div><strong>Note:</strong> These are not commonly-used ways to create pods.</div>
</blockquote></p>
















<h2 id="what-s-next">What&#39;s next</h2>
<ul>
<li>Follow a real world example of <a href="../../../tutorials/configuration/configure-redis-using-configmap/index.html">Configuring Redis using a ConfigMap</a>.</li>
</ul>






				<div class="issue-button-container">
					<p><a href="index.html"><img src="https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/tasks/configure-pod-container/configure-pod-configmap.md?pixel" alt="Analytics" /></a></p>
					
					
					<script type="text/javascript">
					PDRTJS_settings_8345992 = {
					"id" : "8345992",
					"unique_id" : "\/docs\/tasks\/configure-pod-container\/configure-pod-configmap\/",
					"title" : "Configure a Pod to Use a ConfigMap",
					"permalink" : "https:\/\/kubernetes.io\/docs\/tasks\/configure-pod-container\/configure-pod-configmap\/"
					};
					(function(d,c,j){if(!document.getElementById(j)){var pd=d.createElement(c),s;pd.id=j;pd.src=('https:'==document.location.protocol)?'https://polldaddy.com/js/rating/rating.js':'http://i0.poll.fm/js/rating/rating.js';s=document.getElementsByTagName(c)[0];s.parentNode.insertBefore(pd,s);}}(document,'script','pd-rating-js'));
					</script>
					<a href="index.html" onclick="window.open('https://github.com/kubernetes/website/issues/new?title=Issue%20with%20' +
					'k8s.io'+window.location.pathname)" class="button issue">Create an Issue</a>
					
					
					
					<a href="../../../editdocs#docs/tasks/configure-pod-container/configure-pod-configmap.md" class="button issue">Edit this Page</a>
					
				</div>
			</div>
		</section>
		<footer>
    <main class="light-text">
        <nav>
            
            
            
            <a href="../../../home.1">Documentation</a>
            
            <a href="../../../../blog/index.html">Blog</a>
            
            <a href="../../../../partners/index.html">Partners</a>
            
            <a href="../../../../community/index.html">Community</a>
            
            <a href="../../../../case-studies/index.html">Case Studies</a>
            
        </nav>
        <div class="social">
            <div>
                <a href="https://twitter.com/kubernetesio" class="twitter"><span>twitter</span></a>
                <a href="https://github.com/kubernetes/kubernetes" class="github"><span>Github</span></a>
                <a href="http://slack.k8s.io/" class="slack"><span>Slack</span></a>
            </div>
            <div>
                <a href="http://stackoverflow.com/questions/tagged/kubernetes" class="stack-overflow"><span>Stack Overflow</span></a>
                <a href="https://discuss.kubernetes.io" class="mailing-list"><span>Forum</span></a>
                <a href="https://calendar.google.com/calendar/embed?src=nt2tcnbtbied3l6gi2h29slvc0%40group.calendar.google.com" class="calendar"><span>Events Calendar</span></a>
            </div>
            <div>
                <a href="../../../getting-started-guides/index.html" class="button">Get Kubernetes</a>
                <a href="https://git.k8s.io/community/contributors/guide" class="button">Contribute</a>
            </div>
        </div>
        <div id="miceType" class="center">
            &copy; 2018 The Kubernetes Authors | Documentation Distributed under <a href="https://git.k8s.io/website/LICENSE" class="light-text">CC BY 4.0</a>
        </div>
        <div id="miceType" class="center">
            Copyright &copy; 2018 The Linux Foundation&reg;. All rights reserved. The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see our <a href="https://www.linuxfoundation.org/trademark-usage" class="light-text">Trademark Usage page</a>
        </div>
    </main>
</footer>

		<button class="flyout-button" onclick="kub.toggleToc()"></button>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-36037335-10', 'auto');
ga('send', 'pageview');


(function () {
    window.addEventListener('DOMContentLoaded', init)

        
        function init() {
            window.removeEventListener('DOMContentLoaded', init)
                hideNav()
        }

    function hideNav(toc){
        if (!toc) toc = document.querySelector('#docsToc')
        if (!toc) return
            var container = toc.querySelector('.container')

                
                if (container) {
                    if (container.childElementCount === 0 || toc.querySelectorAll('a.item').length === 1) {
                        toc.style.display = 'none'
                            document.getElementById('docsContent').style.width = '100%'
                    }
                } else {
                    requestAnimationFrame(function () {
                        hideNav(toc)
                    })
                }
    }
})();
</script>



	</body>
</html>